//
//  IdentityViewController.m
//  TotalDemo
//
//  Created by gujian on 16/2/14.
//  Copyright © 2016年 gujian. All rights reserved.
//

#import "IdentityViewController.h"
#import "TDViewUtils.h"

@interface IdentityViewController ()<UITextFieldDelegate>

@property (nonatomic, weak) UITextField *checkTextField;

@property (nonatomic, weak) UILabel *produceLbl;

@property (nonatomic, weak) UIButton *checkButton;

@property (nonatomic, weak) UIButton *produceButton;

@end

@implementation IdentityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"身份账号";
    [self setupViews];
}

- (void)setupViews
{
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(15, 15, SCREEN_WIDTH - 30, 30)];
    textField.placeholder = @"请输入身份证号";
    textField.font = [UIFont systemFontOfSize:15.0];
    textField.delegate = self;
    textField.layer.borderWidth = 0.5;
    textField.layer.borderColor = UICOLOR_ARGB(0xffb71e33).CGColor;
    [self.view addSubview:textField];
    self.checkTextField = textField;
    
    UIButton *checkBtn = [TDViewUtils createCustomButton];
    checkBtn.frame = CGRectMake(0, textField.bottom+15, SCREEN_WIDTH, 38);
    [checkBtn setTitle:@"检测身份证号" forState:UIControlStateNormal];
    [checkBtn addTarget:self action:@selector(checkAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:checkBtn];
    self.checkButton = checkBtn;
    
    UILabel *identityLbl = [TDViewUtils createCustomLabel];
    identityLbl.frame = CGRectMake(15, checkBtn.bottom+15, SCREEN_WIDTH-30, 30);
    identityLbl.text = @"身份证号生成区域";
    identityLbl.layer.borderWidth = 0.5;
    identityLbl.layer.borderColor = UICOLOR_ARGB(0xffb71e33).CGColor;
    [self.view addSubview:identityLbl];
    self.produceLbl = identityLbl;
    
    UIButton *produceBtn = [TDViewUtils createCustomButton];
    produceBtn.frame = CGRectMake(0, identityLbl.bottom+15, SCREEN_WIDTH, 38);
    [produceBtn setTitle:@"生成身份证号" forState:UIControlStateNormal];
    [produceBtn addTarget:self action:@selector(produceAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:produceBtn];
    self.produceButton = produceBtn;
    
    
}


- (void)checkAction:(id)sender
{
    UIAlertView *aletView;
    
    if (![NSString isIdentityCard:self.checkTextField.text]) {
        aletView = [[UIAlertView alloc] initWithTitle:@"" message:@"身份证号错误" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        
    }else
        aletView = [[UIAlertView alloc] initWithTitle:@"" message:@"身份证号正确" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
 
    [aletView show];
}


- (void)produceAction:(id)sender
{
    
}


#pragma mark - UITextField delegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    return textField.text.length <= 18;
}

@end
